home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / name.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  4KB  |  151 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        name.c
  13.  * Purpose:     identify name and/or invoke method on it
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     30-May-1993 CPP; Created.
  16.  *              13-January-1995 CPP (1.19) use <string.h> for ANSI compat
  17.  *              20-Jan-1995 CPP; (1.23) Use GFFT Icon Tooltypes (here...
  18.  *                allow '=' as separator)
  19.  * Comments:    (1) Error display puts a (^) below first bad character
  20.  */
  21.  
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <ctype.h>
  25. #include "gfft.h"
  26. #include "errcodes.h"
  27.  
  28. #define SEPARATOR(ch) (ch == ' ' || ch == '=' || ch == '\t')
  29.  
  30. static int cindex = 0;
  31.  
  32. Name_Info_St *invoke_method (char *command, 
  33.                   Name_Info_St *command_name_list)
  34. {
  35.     Name_Info_St *this_command;
  36.     char *argument_string;
  37.  
  38.     this_command = identify_name (command, command_name_list, TRUE);
  39.     if (command[cindex] == '\0')
  40.     {
  41.     argument_string = &command[cindex];
  42.     }
  43.     else
  44.     {
  45.     argument_string = &command[ cindex + 1];
  46.     }
  47.     (*this_command->cfunction) (argument_string);
  48.     return this_command;
  49. }
  50.  
  51.  
  52. /*
  53.  * if report_error is TRUE,
  54.  * there will be no direct return on error
  55.  * only longjmp
  56.  */
  57. Name_Info_St *identify_name (char *command, 
  58.                 Name_Info_St *command_name_list, 
  59.                 BOOLEAN report_error)
  60. {
  61.     int i;
  62.     int lastmatch = 0;
  63.     int error_code = NO_SUCH_COMMAND;
  64.     int command_offset;
  65.  
  66.     if (command[0] == '\0')
  67.     {
  68.     if (report_error)
  69.     {
  70.         RAISE_ERROR (NOTHING_SPECIAL); /* longjmp outa here! */
  71.     }
  72.     else
  73.     {
  74.         return NULL;
  75.     }
  76.     }
  77.  
  78.     for (i = 0; strlen (command_name_list[i].full_string); i++)
  79.     {
  80. /*
  81.  * First, find a minimum string that matches
  82.  */
  83.     cindex = 0;
  84.     while (command[cindex] && command_name_list[i].min_string[cindex] &&
  85.            !SEPARATOR (command[cindex]) &&
  86.            toupper (command[cindex]) == toupper 
  87.            (command_name_list[i].min_string[cindex]))
  88.     {
  89.         cindex++;
  90.         if (cindex > lastmatch)
  91.         {
  92.         lastmatch = cindex;
  93.         }
  94.     }
  95.     if (command_name_list[i].min_string[cindex] != '\0')
  96.         {
  97.         if (command[cindex] == '\0' || SEPARATOR (command[cindex]))
  98.         {
  99.         error_code = AMBIGUOUS_COMMAND;
  100.         }
  101.         continue;
  102.     }
  103. /*
  104.  * Then, insure that following characters don't mismatch
  105.  */
  106.     while (command[cindex] && command_name_list[i].full_string[cindex] &&
  107.            !SEPARATOR (command[cindex]) &&
  108.            toupper (command[cindex]) == toupper 
  109.            (command_name_list[i].full_string[cindex]))
  110.     {
  111.         cindex++;
  112.         if (cindex > lastmatch)
  113.         {
  114.         lastmatch = cindex;
  115.         }
  116.     }
  117.     if (command[cindex] == '\0' || SEPARATOR (command[cindex]))
  118.     {
  119.         return &command_name_list[i];  /* SUCCESSFUL return */
  120.     }
  121.     continue;
  122.     }
  123. /*
  124.  * No command has matched completely!
  125.  */
  126.     command_offset = command - Command;
  127.     if (command_offset)
  128.     {
  129.     if (error_code == NO_SUCH_COMMAND)
  130.     {
  131.         error_code = NO_SUCH_ARGUMENT;
  132.     }
  133.     else if (error_code == AMBIGUOUS_COMMAND)
  134.     {
  135.         error_code = AMBIGUOUS_ARGUMENT;
  136.     }
  137.     }
  138.     if (report_error)
  139.     {
  140.     command_error_message (error_code, command + lastmatch);
  141.     RAISE_ERROR (NOTHING_SPECIAL); /* longjmp outa here! */
  142.     }
  143.     else
  144.     {
  145.     return NULL;
  146.     }
  147. /*
  148.  * all returns or jumps above
  149.  */
  150. }
  151.